package com.example.train_operate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.train_operate.dto.LoginDTO;
import com.example.train_operate.entity.User;
import com.example.train_operate.service.UserService;
import com.example.train_operate.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Api(tags = "用户管理")
@RequestMapping({"/user"})
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginDTO loginDTO) {
        return userService.login(loginDTO);
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        return userService.register(user);
    }

    /**
     * 获取用户信息列表
     * @return
     */
    @ApiOperation(("获取用户信息列表"))
    @GetMapping("/getUserList")
    public Result getUserList(){
        return userService.getUserList();
    }

    /**
     * 退出登录
     * @return
     */
    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public Result logout(){
        return userService.logout();
    }

    /**
     * 获取所有在线用户
     * @return
     */
    @ApiOperation("获取所有在线用户")
    @GetMapping("/online")
    public Result getOnlineUser(@RequestParam(required = false) String excludeUserId){
        return userService.getAllOnlineUsers(excludeUserId);
    }

    /**
     * 获取Android设备列表
     * @return
     */
    @ApiOperation("获取Android设备列表")
    @GetMapping("/android-devices")
    public Result getAndroidDevices(@RequestParam(required = false) String excludeUserId){
        return userService.getAndroidDevices(excludeUserId);
    }

    /**
     * 获取在线用户统计
     * @return
     */
    @ApiOperation("获取在线用户统计")
    @GetMapping("/stats")
    public Result getStats(){
        return userService.getStats();
    }

    /**
     * 删除用户
     * @param userId
     * @return
     */
    @ApiOperation("删除用户")
    @DeleteMapping("/delete/{userId}")
    public Result deleteUser(@PathVariable Integer userId){
        return userService.deleteUser(userId);
    }

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @ApiOperation("修改用户信息")
    @PutMapping("/update")
    public Result updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    /**
     * 修改密码
     * @param user
     * @return
     */
    @ApiOperation("修改密码")
    @PutMapping("/updatePassword")
    public Result updatePassword(@RequestBody User user){
        return userService.updatePassword(user);
    }
}